import axios from 'axios'
// eslint-disable-next-line no-unused-vars
import NProgress from 'nprogress'
// axios.defaults.baseURL = 'http://www.kirrito.top'
axios.defaults.baseURL =  window.location.origin

// 请求拦截 获取请求对象
axios.interceptors.request.use(function (config) {
  NProgress.start()
  // 获取之前登录返回的token
  // 把token通过请求头的方式传递给后台
  const token = localStorage.getItem('token')
    config.headers.token = token
    return config
  }, function (error) {
    return Promise.reject(error)
})

// 响应拦截 截取结果值
axios.interceptors.response.use(function (response) {
  NProgress.done()
  return response.data
}, function (error) {
  return Promise.reject(error)
})

export default axios
